{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-07-04T02:35:03.495032Z",
     "start_time": "2020-07-04T02:35:03.490760Z"
    }
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import pickle\n",
    "import json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-07-04T02:35:03.773941Z",
     "start_time": "2020-07-04T02:35:03.670311Z"
    }
   },
   "outputs": [],
   "source": [
    "with open('../result.pkl', 'rb') as f:\n",
    "    results = pickle.load(f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-07-04T02:35:03.995211Z",
     "start_time": "2020-07-04T02:35:03.966184Z"
    }
   },
   "outputs": [],
   "source": [
    "with open('../file_info.pkl', 'rb') as f:\n",
    "    info = pickle.load(f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-07-04T02:35:05.401225Z",
     "start_time": "2020-07-04T02:35:04.534748Z"
    }
   },
   "outputs": [],
   "source": [
    "for i, image_results in enumerate(results):\n",
    "    for j, class_detection in enumerate(image_results):\n",
    "        for detection in class_detection:\n",
    "            temp = dict()\n",
    "            temp['score'] = float(detection[4])\n",
    "            temp['tag'] = 1\n",
    "            temp['box'] = [float(detection[0]), float(detection[1]), float(detection[2])-float(detection[0]), float(detection[3])-float(detection[1])]\n",
    "            if detection[4]>0.5:\n",
    "                info[i]['dtboxes'].append(temp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-07-04T02:35:06.913302Z",
     "start_time": "2020-07-04T02:35:06.586168Z"
    }
   },
   "outputs": [],
   "source": [
    "with open('submission.txt', 'w') as f:\n",
    "    for r in info:\n",
    "        f.write(json.dumps(r)+'\\n')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
